package demoMod.invincibleOne.patches;

import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.cards.invincible.AbstractInvincibleCard;
import demoMod.invincibleOne.enums.CardTagsEnum;

public class CardGroupPatch {
    @SpirePatch(
            clz = CardGroup.class,
            method = "initializeDeck"
    )
    public static class PatchInitializeDeck {
        public static void Postfix(CardGroup cardGroup, CardGroup masterDeck) {
            if (cardGroup == AbstractDungeon.player.drawPile) {
                cardGroup.group.removeIf(c -> c.hasTag(CardTagsEnum.ALERT));
                for (AbstractCard c: cardGroup.group) {
                    if (c instanceof AbstractInvincibleCard) {
                        ((AbstractInvincibleCard) c).onInitDeck();
                    }
                }
            }
        }
    }

    @SpirePatch(
            clz = CardGroup.class,
            method = "removeCard",
            paramtypez = {
                    AbstractCard.class
            }
    )
    public static class PatchRemoveCard {
        public static void Prefix(CardGroup group, AbstractCard card) {
            if (group.type == CardGroup.CardGroupType.MASTER_DECK) {
                InvincibleOneMod.bingoPanel.getSlots().forEach(slot -> slot.getBingoItem().onRemoveCard(card));
            }
        }
    }
}
